home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / MAGAZINE / @FALCON / FALK'MAG.2 / SOURCE.COD / LIGNE / INTERPOL.S < prev   
Encoding:
Text File  |  1995-10-23  |  7.4 KB  |  346 lines

  1. * Routine de ligne en True Color (640*400)
  2.  
  3. wait_sys macro
  4.      move.w sr,-(sp)
  5.      andi.w #$fbff,sr
  6.      move.l $466.w,d0
  7. wait_sys\@
  8.      cmp.l $466.w,d0
  9.      beq.s wait_sys\@
  10.      move.w (sp)+,sr
  11.      endm
  12.  
  13.  
  14.      section TEXT
  15. * passage en superviseur
  16.      clr.l -(sp)
  17.      move.w #32,-(sp)
  18.      trap #1
  19.      addq.l #6,sp
  20.      
  21. * demande de résolution
  22.      move.w #-1,-(sp)
  23.      move.w #$58,-(sp)        * Vsetmode
  24.      trap #14
  25.      adda.l #4,sp
  26.      move.w d0,ancien_mode
  27. * adresse physique
  28.      move.w #2,-(sp)          * Physbase
  29.      trap #14
  30.      adda.l #2,sp 
  31.      move.l d0,ancien_phys
  32. * adresse logique
  33.      move.w #3,-(sp)          * Logbase
  34.      trap #14
  35.      adda.l #2,sp
  36.      move.l d0,ancien_log
  37.  
  38. * Mise en place de la nouvelle résolution
  39. * calcul de l'adresse écran (qui doit être un mutiple de 4)
  40.      move.l #ecran+4,d0
  41.      andi.b #$FC,d0           * il  suffit d'annuler les 2  bits  de  poid 
  42.                               * faible
  43.      move.l d0,adr_ecran      * on stocke l'adresse écran
  44.      move.w #%0000000100101100,-(sp) * entrelacé/80 colonnes/65536 couleurs
  45.                                      * TV/PAL/pas d'overscan
  46.      move.w #3,-(sp)
  47.      move.l d0,-(sp)          * écran physique = écran logique
  48.      move.l d0,-(sp)
  49.      move.w #5,-(sp)          * Setscreen
  50.      trap #14
  51.      adda.l #14,sp
  52.  
  53. bouc
  54.      wait_sys
  55.      * permet d'obtenir le temps machine en bleu
  56.      move.w #$0000,$ff9800
  57. * appel de la routine de ligne
  58. * D0 : X de départ
  59. * D1 : Y de départ
  60. * D2 : X de d'arrivé
  61. * D3 : Y de d'arrivé
  62. * D4 : couleur
  63.      
  64.      rept 10          * tracer de 10 ligne
  65.      move.w #0,d0
  66.      move.w #0,d1
  67.      move.w #639,d2
  68.      move.w #399,d3
  69.      move.w #%0011000011000110,d4
  70.      bsr ligne           * trace la ligne    
  71.      endr
  72.  
  73.      move.w #$ffff,$ff9800
  74.      * repetion tant que la touche espace
  75.      * n'est pas frappée
  76.      
  77.      cmp.b #$39,$fffffc02.w
  78.      bne bouc
  79. * fin du programme
  80.  
  81. * remise en place de la résolution
  82.      move.w ancien_mode,-(sp)
  83.      move.w #3,-(sp)
  84.      move.l ancien_phys,-(sp)
  85.      move.l ancien_log,-(sp)
  86.      move.w #5,-(sp)
  87.      trap #14
  88.      adda.l #14,sp
  89.  
  90. * retour au mode utilisateur
  91.      clr.l -(sp)
  92.      move.w #32,-(sp)
  93.      trap #1
  94.      addq.l #6,sp
  95.  
  96. * retour système
  97.      move.w #0,-(sp)
  98.      trap #1
  99.  
  100. * routine de ligne en 65536 couleurs, 640 points de large
  101. ligne
  102. * recoit en D0 : X, D1 : Y : de départ
  103. *           D2 : X, D3 : Y : d'arrivée
  104. * D4 : couleur sur 32 bits !!
  105. * modifie D0, D1, A0
  106. * stockage de yinc
  107.      move.l #640*2,d7
  108. * calcul de dx dans D5
  109.      move.w d2,d5
  110.      sub.w d0,d5
  111.      beq rout5    
  112. * si dx est nul, ligne verticale !!
  113.      bpl xpasneg1            
  114. * si dx negatif, donc d2<d0
  115. * donc le premier point devient d2,d3
  116.      neg.w d5
  117.      exg.l d2,d0
  118.      exg.l d3,d1
  119. xpasneg1
  120. * on trace toujours vers les x croissants
  121. * calcul de dy
  122.      move.w d3,d6
  123.      sub.w d1,d6
  124.      beq rout4            
  125. * dy est nul, ligne horizontal    
  126.      bpl ypasneg1
  127. * dy négatif, donc d4<d1
  128.      neg.w d6
  129. * tracé en montant vers la droite
  130. * donc d7=-640*2
  131.      neg.l d7
  132. ypasneg1
  133.      cmp.w d5,d6
  134. * comparaison dx et dy
  135.      bmi rout2     * <0
  136.      beq rout3     * =0 : une diagonale !!!
  137.  
  138. * à la fin : d5 : dx
  139. *            d6 : dy
  140. * routine 1
  141. * ici dx>0, dy>0 et dy>dx
  142. * a pus besoin de d2, d3, et dx après division
  143. rout1
  144. * si dx = 1 : 2 pixels de large !!
  145. * donc il faut rajouter 1 à chaque d
  146.      addq.w #1,d5
  147.      addq.w #1,d6
  148. * décalage de 16 bits pour la division
  149.      swap d5
  150.      clr.w d5
  151.      divu.w d6,d5        
  152. * division de dx par dy + division par 16 bits
  153. * d5 contient la pente : résultat sur 16 bits
  154. * boucle sur d6
  155.      subq.w #1,d6
  156. * calcul d'adresse du 1er point dans a0
  157.      movea.l adr_ecran,a0
  158.      add.w d0,d0
  159.      adda.w d0,a0
  160.      mulu.w #1280,d1
  161.      adda.l d1,a0
  162. * somme = 0
  163.      moveq.l #0,d3    
  164.      * d0 : 
  165.      * d1 : 
  166.      * d2 : 
  167.      * d3 : somme
  168.      * d4 : couleur
  169.      * d5 : pente
  170.      * d6 : delta y
  171.      * d7 : offset pour changement de ligne 
  172. ligneb1
  173.      add.w d5,d3
  174.      bcs lignenx1
  175. * pas de déplacement suivant x
  176.      move.w d4,(a0)
  177.      adda.l d7,a0
  178.      dbra d6,ligneb1
  179.      rts
  180. lignenx1
  181.      move.w d4,(a0)+
  182.      adda.l d7,a0
  183.      dbra d6,ligneb1
  184.      rts
  185.  
  186. * routine 2
  187. * ici dx>0, dy>0 et dy<dx
  188. * a pus besoin de d2, d3, et dy après division
  189. rout2
  190. * correction de d
  191.      addq.w #1,d5
  192.      addq.w #1,d6
  193. * décalage de 16 bits
  194.      swap d6
  195.      clr.w d6
  196.      divu.w d5,d6        
  197. * division de dy par dx + division par 16 bits
  198. * d6 contient la pente : résultat sur 16 bits
  199. * boucle sur d5
  200.      subq.w #1,d5
  201. * calcul d'adresse du 1er point dans a0
  202.      movea.l adr_ecran,a0
  203.      add.w d0,d0
  204.      adda.w d0,a0
  205.      mulu.w #1280,d1
  206.      adda.l d1,a0
  207. * somme = 0
  208.      moveq.l #0,d3
  209.      * d0 : 
  210.      * d1 : 
  211.      * d2 : 
  212.      * d3 : somme
  213.      * d4 : couleur
  214.      * d5 : delta x
  215.      * d6 : pente
  216.      * d7 : offset pour changement de ligne et de pixel
  217. ligneb2
  218.      move.w d4,(a0)+
  219.      add.w d6,d3
  220.      bcc ligneny2            
  221. * pas de déplacement suivant y 
  222.      adda.l d7,a0
  223. ligneny2
  224.      dbra d5,ligneb2
  225.      rts
  226.  
  227. * ici dx>0, dy>0 et dx=dy
  228. * une diagonale!!
  229. * OK
  230. rout3
  231. * calcul d'adresse du 1er point dans a0
  232.      movea.l adr_ecran,a0
  233.      add.w d0,d0
  234.      adda.w d0,a0
  235.      mulu.w #1280,d1
  236.      adda.l d1,a0
  237. * division par 2 de d5
  238.      lsr.w #1,d5
  239.      bcc ligneb3
  240. * si retenue alors nombre impair
  241.      move.w d4,(a0)
  242.      adda.l d7,a0
  243. * ce qui permet d'afficher 2 points par 2 points
  244. ligneb3
  245.      move.w d2,(a1)+
  246.      adda.l d7,a1
  247.      move.w d2,(a1)+
  248.      adda.l d7,a1
  249.      dbra d5,ligneb3
  250.      rts
  251.  
  252. * ici dy est nul
  253. * et dx positif
  254. * ligne horizontale
  255. * OK
  256. rout4
  257. * calcul d'adresse du 1er point dans a0
  258.      movea.l adr_ecran,a0
  259.      add.w d0,d0
  260.      adda.w d0,a0
  261.      mulu.w #1280,d1
  262.      adda.l d1,a0
  263. * division de d5 par 2
  264.      lsr.w #1,d5
  265.      bcc ligneb4
  266. * d5 : nombre impaire
  267.      move.w d4,(a0)+
  268. ligneb4
  269.      move.l d4,(a0)+
  270. * 2 pixels d'un coup !
  271.      dbra d5,ligneb4
  272.      rts
  273.  
  274. * ici dx est nul
  275. * et dy est inconnu
  276. * ligne verticale
  277. * OK
  278. rout5
  279.      move.w d3,d6
  280.      sub.w d1,d6
  281.      bmi rout5_yneg
  282.      beq rout6
  283. * calcul d'adresse du 1er point dans a0
  284.      movea.l adr_ecran,a0
  285.      add.w d0,d0
  286.      adda.w d0,a0
  287.      mulu.w #1280,d1
  288.      adda.l d1,a0
  289. * division par 2 de d6
  290.      lsr.w #1,d6
  291.      bcc ligneb5
  292. * d6 : nombre impaire
  293.      move.w d4,(a0)
  294.      adda.l d7,a0
  295. ligneb5
  296.      move.w d4,(a0)
  297.      adda.l d7,a0
  298.      move.w d4,(a0)
  299.      adda.l d7,a0
  300.      dbra d6,ligneb5
  301.      rts
  302. rout5_yneg
  303.      neg.w d6
  304. * calcul d'adresse du 1er point dans a0
  305.      movea.l adr_ecran,a0
  306.      add.w d0,d0
  307.      adda.w d0,a0
  308.      mulu.w #1280,d1
  309.      adda.l d1,a0
  310. * division par deux de d6
  311.      lsr.w #1,d6
  312.      bcc ligneb5_yneg
  313. * d6 : nombre impair
  314.      move.w d4,(a0)
  315.      adda.l d7,a1
  316. ligneb5_yneg
  317.      move.w d4,(a0)
  318.      adda.l d7,a0
  319.      move.w d4,(a0)
  320.      adda.l d7,a0
  321.      dbra d6,ligneb5_yneg
  322.      rts
  323.  
  324. * deltax est nul
  325. * deltay est nul
  326. * c'est un point
  327. * OK
  328. rout6
  329. * calcul d'adresse du 1er point dans a0
  330.      movea.l adr_ecran,a0
  331.      add.w d0,d0
  332.      adda.w d0,a0
  333.      mulu.w #1280,d1
  334.      adda.l d1,a0
  335.      move.w d4,(a0)
  336.      rts
  337.  
  338.      section BSS
  339.      EVEN
  340. * variable
  341. * initialisation
  342. ancien_mode    ds.w 1   
  343. ancien_phys    ds.l 1
  344. ancien_log     ds.l 1
  345. adr_ecran      ds.l 1
  346. ecran          ds.b 640*2*400+4